#include<iostream>

#include"Socket.hpp"
#include"Protocol.hpp"


int main(int argc,char* argv[])
{
    if(argc!=3)
    {
        std::cout<<"Usage: "<<argv[0]<<" serverip serverport "<<std::endl;
    }
    std::string serverip=argv[1];
    uint16_t serverport=std::stoi(argv[2]);
    Net_Work::Socket* s=new Net_Work::TcpSocket();
    if(!s->BuidConnectSocketMethod(serverip,serverport))
    {
        std::cerr<<"connect "<<serverip<<":"<<serverport<<"faild"<<std::endl;
    }
    std::cout<<"connect "<<serverip<<":"<<serverport<<"succeed"<<std::endl;

    // std::string message="hello world";
    // write(s->GetSocket(),message.c_str(),message.size());

    //send和sendto和write关系
    //sleep(10);
    std::unique_ptr<Factory> factory = std::make_unique<Factory>();
    std::shared_ptr<Request> req = factory->BuildRequest(10,20,'+');
    while(true)
    {
        send(s->GetSocket(), &(*req), sizeof(*req), 0);
        req->AddPrint();
        sleep(1);
    }
    s->CloseSockfd();
    return 0;
}